package cn.kgc.tangcco.anyang.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cn.kgc.tangcco.anyang.commons.PageParam;
import cn.kgc.tangcco.anyang.pojo.Clazz;
import cn.kgc.tangcco.anyang.service.ClazzService;

@RestController
@RequestMapping(value = "/clazz")
public class ClazzController {
	@Autowired
	private ClazzService clazzService;
	@RequestMapping(value = "/showClazzs")
	public Map<String, Object> showClazzs(PageParam pageParam){
		// 从查询参数中获取分页信息对象
		// PageParam pageParam = new PageParam();
		// 调用PageHelper传入分页参数
		PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
		Map<String, Object> map = clazzService.queryClazzs(new HashMap<String, Object>());
		PageInfo<Clazz> pageInfo = null;
		switch (map.get("errorCode").toString()) {
		case "0":
			List<Clazz> clazzs = (List<Clazz>) map.get("data");
			pageInfo = new PageInfo<Clazz>(clazzs);
			map.clear();
			map.put("pageInfo", pageInfo);
			break;

		default:
			System.out.println("我也是有底线的");
			break;
		}
		return map;
	}
}
